package com.popo.android.activity;

import java.io.IOException;

import com.popo.android.R;

import android.app.Activity;
import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Environment;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

public class WallpaperSet extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		WallpaperManager wallpaperManager = (WallpaperManager) getSystemService(WALLPAPER_SERVICE);
		String jpg =Environment.getExternalStorageDirectory().getAbsolutePath()+"/jj.jpg";
		Bitmap  bd= BitmapFactory.decodeFile(jpg);
				
		setContentView(R.layout.wallpageset);
		
		WindowManager wm = getWindowManager();
		//
		
	
		
		
//		try {
//			wallpaperManager.setBitmap(bd);
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		
//		this.finish();
		System.out.println("onCreate");
	}
	
	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		// TODO Auto-generated method stub
		super.onWindowFocusChanged(hasFocus);
		View root =getWindow().findViewById(Window.ID_ANDROID_CONTENT);
		
		
		ImageView wallpaperSrc = (ImageView) findViewById(R.id.wallpagesrc);
		
//		LayoutParams params = wallpaperSrc.getLayoutParams();
//		params.width=((root.getWidth()*8)/10);
//		params.height=params.width*root.getHeight()/root.getWidth();
//		System.out.println(params.width+","+params.height+":"+root.getHeight()+","+root.getWidth());
		

//		wallpaperSrc.setLayoutParams(params );
//		root.invalidate();
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		System.out.println("onResume");
		
	}
	
	@Override
	protected void onPostCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onPostCreate(savedInstanceState);
		System.out.println("onPostCreate");
	}
}
